/**
 * @author gsc
 * @description vuex mutation封装，间接修改state数据
 */
import {
  RECEIVE_USER_INFO,
	RECEIVE_CURRENT_ROLE,
	RECEIVE_LIST_SCROLL,
	RESET_USER_INFO,
	RECEIVE_FILTER,
	RECEIVE_MENUS,
	RECEIVE_SYSTEM_CONFIG,
} from './mutation-types'
import { listFilter } from '@/api/request/business'
export default {
  
  /**
	 * @description 记录用户登录信息
	 * @param {Object} userInfo 用户登录信息
	 * @param {String} userInfo.token 凭据 
	 * @param {Array} userInfo.roles 角色对象数组 
	 * @param {Array} userInfo.auths 当前角色拥有的权限对象数组 
	 */
  recordUserInfo({commit}, userInfo) {
    commit(RECEIVE_USER_INFO, { userInfo })
  },

	recordCurrentRoleName({commit}, currentRoleName) {
		commit(RECEIVE_CURRENT_ROLE, { currentRoleName })
	},
  
	/**
	 * @description 记录用户菜单
	 * @param {Array} menus 
	 */
	recordMenus({commit}, menus) {
		commit(RECEIVE_MENUS, { menus })
	},

	/**
	 * @description 记录系统配置
	 * @param {Array} systemConfig 系统配置信息 
	 */
	recordSystemConfig({commit}, systemConfig) {
		commit(RECEIVE_SYSTEM_CONFIG, { systemConfig })
	},
	// 记录列表页滚动缓存
	recordListScroll({commit}, listScroll) {
		commit(RECEIVE_LIST_SCROLL,{ listScroll })
	},

	// 异步获取过滤条件
	async recordFilter({commit}, options) {
		const { body } = await listFilter({ beanId: options.beanId, categoryName: 'DM_CHECK_CHECKSTATUS' })
    const filterOrigin = body.data.item['DM_CHECK_CHECKSTATUS']
		const filter = filterOrigin.map( fo => {
			return {
				name: fo.name,
				code: fo.code
			}
		})
		commit(RECEIVE_FILTER, { filter, beanId: options.beanId })
	},
  
	// 登出
	logout({commit}) {
		commit(RESET_USER_INFO)
	}
}